package uit.com.project.iCampus.dao.hibernate;

import java.util.List;

import uit.com.project.iCampus.dao.BuildingInfoDAO;
import uit.com.project.iCampus.model.BuildingInfo;
import uit.com.project.iCampus.model.BuildingTypeEnum;

public class BuildingInfoDAOHibernate extends GenericHibernateDAO<BuildingInfo, Long> implements BuildingInfoDAO{

	/**
	 * search BuildngInfo With BuildingTypeEnum
	 * 
	 * @param buildingTypeEnum
	 * @return List<BuildingInfo>
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BuildingInfo> searchBuildngInfoWithBuildingTypeEnum(
			String buildingTypeString) {
		BuildingTypeEnum buildingTypeEnum = BuildingTypeEnum.valueOf(buildingTypeString);
		return getSession()
				.createQuery(
						"FROM BuildingInfo AS BldInfo WHERE BldInfo.buidingTypeEnum = :buidingTypeEnum")
				.setParameter("buidingTypeEnum", buildingTypeEnum)
				.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<BuildingInfo> getListBuildngInfoInRadius(float botLat,
			float topLat, float leftLon, float rightLon) {
		String query = " select b from BuildingInfo b WHERE " +
				"( b.latitude between :botLat and :topLat )" +
				" and ( b.longitude between :leftLon and :rightLon )"
				;
		return getSession()
				.createQuery(query)
				.setParameter("botLat", botLat)
				.setParameter("topLat", topLat)
				.setParameter("leftLon", leftLon)
				.setParameter("rightLon", rightLon)
				.list();
	}
	
}